import net from "net";
export let socketHandle = (getData) => {
  let str = "";
  // console.log(getData);
  return new Promise((resolve, reject) => {
    //创建客户端的 socket 服务器
    const socketServer = new net.Socket();

    // 与tcp服务器创建连接
    socketServer.connect(999, "127.0.0.1", () => {
      // 向 tcp 服务器发送数据
      socketServer.write(getData);
    });

    //接收 TCP 服务端传过来的数据
    socketServer.on("data", (data) => {
      // console.log(data.toString());
      // str += data.toString()
      // console.log(`接收过来的数据${data.toString()}`);
      // resolve(data.toString())
      str += data.toString();
    });

    setTimeout(() => {
      resolve([str]);
    }, 200);
  });
};
